<?php

namespace app\admin\controller;

use app\model\Template as TemplateModel;
use think\Request;
use app\admin\validate\Template as TemplateValidate;

class Template extends Controller
{
    protected function initialize()
    {
        parent::initialize();
    }

    //模板列表
    public function templateList()
    {
         $data = input('post.');
         $model = new TemplateModel();
         return $model->showList($data);
    }

    //设置状态
    public function templateStatus()
    {
        $data = input('post.');
        $model = new TemplateModel();
        return $model->optionStatus($data);
    }

    //设置状态
    public function editTemplate()
    {
        $data = input('post.');
        $model = new TemplateModel();
        return $model->editTemplate($data);
    }


    /**
     *  新增推广模板
     */
    public function addTemplate(Request $request, TemplateValidate $validate)
    {
        $params = $request->only(['template_name', 'pre_url', 'sort', 'template_img', 'status', 'serv_types']);
        $result = $validate->scene('add_template')->check($params);
        if (!$result) {
            return fail($validate->getError());
        }
        $model = new TemplateModel();
        return $model->addTemplate($params);
    }
}
